﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net;
using System.IO;
using System.Drawing;

namespace B12_Ex03_Eran_053094363_Assaf_036722999
{
    public class AsyncImageLoader
    {
        public string ImageURL { get; set; }

        public Image ResultImage { get; set; }

        public void GetImage()
        {
            if (ImageURL != null)
            {
                try
                {
                    WebRequest request = WebRequest.Create(ImageURL);
                    WebResponse response = request.GetResponse();
                    using (System.IO.Stream responseStream = response.GetResponseStream())
                    {
                        ResultImage  = Image.FromStream(responseStream);
                    }
                }
                catch (Exception)
                {
                    ResultImage = Properties.Resources.facebook_default;
                }
            }
        }
    }
}
